package bean;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import resources.dao.CompanyDAO;
import resources.pojo.pe_cmpany;
import resources.util.Tool;
import resources.util.HVUtil;

@ManagedBean(name="companyInfoBean")
@SessionScoped
public class CompanyInfo implements Serializable{
	
	private String value;
	private static final long serialVersionUID = 1L;
	
	private pe_cmpany company = null;
	String message;
	
	public void onload(){
		if(!Tool.isPostBack()){
			Tool.message(message);
			message=null;
			HVUtil.open();
			company = CompanyDAO.getCompanyInfo();
			HVUtil.close();
		}
	}
	
	public void onloadUpdate(){
		if(company == null){
			Tool.redirect("company-info.html");
		}
	}

	public void update(){
		HVUtil.open();
		if(CompanyDAO.update("update", company)){
			message = Tool.getKey("update-sucessfully") ;
			Tool.redirect("company-info.html");
		}
		HVUtil.close();
	}
	
	public void setCompany(pe_cmpany company) {
		this.company = company;
	}

	public pe_cmpany getCompany() {
		return company;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getValue() {
		return value;
	}
}
